<?php
include_once 'MySQLDAO.php';

require "characteristics.class.php";

/**
 * Definition of Class Hotelcharacteristics
 * This class represents a data access object for the database table 'hotelcharacteristics'.
 */
class Hotelcharacteristics {


	public $dao = null;

	private $i = 1;

	/**
	 * associated database field: hotelId, type: int, is nullable: false
	 */
	private $hotelId  = 0;

	/**
	 * associated database field: characteristicId, type: int, is nullable: false
	 */
	private $characteristicId  = 0;

	private $hotels = null;

	private $characteristics = null;



	/**
	 * Default constructor
	 * @param value some value
	 */
	function __construct(){
		$this->dao = new MySQLDao("HotelCharacteristics");
	}


	/**
	 * Initialize the business object with data read from the DB.
	 * @param row database row array containing the values from one read record
	 */
	public function init($row){
		if(isset($row['hotelId'])) $this->hotelId = $row['hotelId'];
		if(isset($row['characteristicId'])) $this->characteristicId = $row['characteristicId'];
	}


	/**
	 * Returns the string representation for this object
	 * @param escapeQuotationMarks boolean value to indicate if quotation marks in value strings should be escaped, default value is true
	 * @return String String representation of Hotelcharacteristics
	 */
	public function toString($escapeQuotationMarks=true){
		$s = '[';
		$s .= 'hotelId: '.(($escapeQuotationMarks===true) ? addslashes($this->hotelId) : $this->hotelId).', ';
		$s .= 'characteristicId: '.(($escapeQuotationMarks===true) ? addslashes($this->characteristicId) : $this->characteristicId);
		$s .= ']';
		return $s;
	}


	/**
	 * Returns the JSON (JavaScript Object Notation) string representation for this object
	 * @return String JSON representation of Hotelcharacteristics
	 */
	public function toJSONString(){
		$fieldValues = array ("hotelId"=>$this->hotelId, "characteristicId"=>$this->characteristicId);
		return json_encode($fieldValues);
	}


	/**
	 * Returns a HTML representation of this object using DIVs for formatting via css
	 * @param escapeHTML boolean value to indicate if value strings should be html escaped, default value is true
	 * @return String the HTML representation of the Hotelcharacteristics object
	 */
	public function toHTMLString($escapeHTML=true){
		$htmlCode = "<div class=\"hotelcharacteristics\">\n";
		$htmlCode .= '	<div class="hotelcharacteristics_hotelId">'.(($escapeHTML===true) ? htmlspecialchars($this->hotelId) : $this->hotelId)."</div>\n";
		$htmlCode .= '	<div class="hotelcharacteristics_characteristicId">'.(($escapeHTML===true) ? htmlspecialchars($this->characteristicId) : $this->characteristicId)."</div>\n";
		$htmlCode .= "</div>\n";
		return $htmlCode;
	}
	/*
	public function getData($where) {
		$rows = $this->dao->getData($where);
		return $rows;
	}*/


	public static function loadAll(){
		$hotelcharacteristics = new Hotelcharacteristics();
		$rows = $hotelcharacteristics->dao->getData("");
		$hotelcharacteristicss = array();
		for ($index = 0; $index < sizeof($rows); $index++) {
			$d = new Hotelcharacteristics();
			$d->init($rows[$index]);
			array_push($hotelcharacteristicss,$d);
		}
		return $hotelcharacteristicss;
	}


	/**
	 * Load the Hotelcharacteristics uniquely by its primary key.
	 * @param characteristicId the primary key
	 * @param hotelId the primary key
	 * @return Hotelcharacteristics Instance of {@link Hotelcharacteristics}
	 */
	public static function loadUnique($hotelId, $characteristicId){
		$hotelcharacteristics = new Hotelcharacteristics();
		$rows = $hotelcharacteristics->dao->getData("`hotelId`='$hotelId' AND `characteristicId`='$characteristicId'");
		$hotelcharacteristics->init($rows[0]);
		return $hotelcharacteristics;
	}


	/**
	 * Load all records of Hotelcharacteristics uniquely by its foreign keys:
	 * characteristicId
	 * @param characteristicId foreign key
	 * @return array of Instance of {@link Hotelcharacteristics}
	 */
	public static function loadByFKCharacteristicid($characteristicId){
		$hotelcharacteristics = new Hotelcharacteristics();
		$rows = $hotelcharacteristics->dao->getData("`characteristicId`='$characteristicId'");
		$hotelcharacteristicss = array();
		for ($index = 0; $index < sizeof($rows); $index++) {
			$d = new Hotelcharacteristics();
			$d->init($rows[$index]);
			array_push($hotelcharacteristicss,$d);
		}
		return $hotelcharacteristicss;
	}


	/**
	 * Load all records of Hotelcharacteristics uniquely by its foreign keys:
	 * hotelId
	 * @param hotelId foreign key
	 * @return array of Instance of {@link Hotelcharacteristics}
	 */
	public static function loadByFKHotelid($hotelId){
		$hotelcharacteristics = new Hotelcharacteristics();
		$rows = $hotelcharacteristics->dao->getData("`hotelId`='$hotelId'");
		$hotelcharacteristicss = array();
		for ($index = 0; $index < sizeof($rows); $index++) {
			$d = new Hotelcharacteristics();
			$d->init($rows[$index]);
			array_push($hotelcharacteristicss,$d);
		}
		return $hotelcharacteristicss;
	}


	/**
	 * Insert this object into the DB
	 * @return number new id (auto increment value) genereated
	 */
	public function insert(){
		$list = array("hotelId"=>$this->hotelId, "characteristicId"=>$this->characteristicId);
		return $this->dao->insertRecord($list);
	}


	/**
	 * Update this object into the DB
	 * @return number the number of updated records
	 */
	public function update(){
		$list = array("hotelId"=>$this->hotelId, "characteristicId"=>$this->characteristicId);
		$where = "`hotelId`='$hotelId' AND `characteristicId`='$characteristicId'";
		return $this->dao->updateRecord($list,$where);
	}


	/**
	 * Initialize the business object with data read from the DB.
	 */
	public function initPOST(){
		if (isset($_POST['hotelId'])){
			$this->hotelId = $_POST['hotelId'];
		}
		if (isset($_POST['characteristicId'])){
			$this->characteristicId = $_POST['characteristicId'];
		}
	}


	/**
	 * Initialize the business object with data read from the DB.
	 */
	public function initGET(){
		if (isset($_GET['hotelId'])){
			$this->hotelId = $_GET['hotelId'];
		}
		if (isset($_GET['characteristicId'])){
			$this->characteristicId = $_GET['characteristicId'];
		}
	}


	/**
	 * Returns the value from the database field hotelId.
	 * In the database the field hotelId is of type int.
	 * The database field is NOT nullable.
	 * @return String the value of the field
	 */
	public function getHotelId(){
		return $this->hotelId;
	}


	/**
	 * Set the value from the database field hotelId.
	 * In the database the field hotelId is of type int.
	 * The database field is NOT nullable.
	 * @param hotelId String with the value for the field to be set
	 */
	public function setHotelId($hotelId){
		$this->hotelId = $hotelId;
	}


	/**
	 * Returns the value from the database field characteristicId.
	 * In the database the field characteristicId is of type int.
	 * The database field is NOT nullable.
	 * @return String the value of the field
	 */
	public function getCharacteristicId(){
		return $this->characteristicId;
	}


	/**
	 * Set the value from the database field characteristicId.
	 * In the database the field characteristicId is of type int.
	 * The database field is NOT nullable.
	 * @param characteristicId String with the value for the field to be set
	 */
	public function setCharacteristicId($characteristicId){
		$this->characteristicId = $characteristicId;
	}


	/**
	 * Returns an instance of the linked Hotels object.
	 * A One to Many (1:n) relation exists between the Hotelcharacteristics and the Hotels table.
	 * @return Hotels the linked instance of Hotels
	 */
	public function getHotels(){
		if($this->hotels == null){
			$this->hotels = Hotels::loadUnique($this->hotelId);
		}
		return $this->hotels;
	}


	/**
	 * Set a link to a related Hotels instance
	 * @param targetObjectInstanceName instance of Hotels to be linked to this object instance
	 */
	public function setHotels($hotels){
		$hotels->hotelId = $this->hotelId;
		$this->hotels = $hotels;
	}


	/**
	 * Returns an instance of the linked Characteristics object.
	 * A One to Many (1:n) relation exists between the Hotelcharacteristics and the Characteristics table.
	 * @return Characteristics the linked instance of Characteristics
	 */
	public function getCharacteristics(){
		if($this->characteristics == null){
			$this->characteristics = Characteristics::loadUnique($this->characteristicId);
		}
		return $this->characteristics;
	}


	/**
	 * Set a link to a related Characteristics instance
	 * @param targetObjectInstanceName instance of Characteristics to be linked to this object instance
	 */
	public function setCharacteristics($characteristics){
		$characteristics->characteristicId = $this->characteristicId;
		$this->characteristics = $characteristics;
	}
}
?>